def tree_move_away(roadLength,startPosition,endPosition):
    startPosition,endPosition=sorted([startPosition,endPosition])
    roadLength[startPosition:endPosition+1]=[0]*(endPosition-startPosition+1)
def main():
    l,m = map(int,input().split())
    tree=[1]*(l+1)
    for i in range(m):
        u,v = map(int,input().split())
        tree_move_away(tree,u,v)
    print(sum(tree))

main()